import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:libflutter/weather/HomeScreen.dart';
import 'package:libflutter/weather/HourlyScreen.dart';
import 'package:libflutter/weather/WeeklyScreen.dart';
import 'package:provider/provider.dart';

class TestWeacherAppWidget extends StatelessWidget {
  const TestWeacherAppWidget({super.key});
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) {
        return WeatherProvider();
      },
      child: MaterialApp(
        title: 'Flutter Weather',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          appBarTheme: const AppBarTheme(
            iconTheme: IconThemeData(
              color: Colors.blue,
            ),
            elevation: 0,
          ),
          scaffoldBackgroundColor: Colors.white,
          primaryColor: Colors.blue,
          visualDensity: VisualDensity.adaptivePlatformDensity,
          colorScheme: ColorScheme.fromSwatch().copyWith(secondary: Colors.white),
        ),
        home: const HomeScreen(),
        routes: {
          WeeklyScreen.routeName: (myCtx) => const WeeklyScreen(),
          HourlyScreen.routeName: (myCtx) => const HourlyScreen(),
        },
      ),
    );
  }
}

class WeatherProvider with ChangeNotifier {

  // 这是一个提供者 在这里提供数据的支持
  int _count = 0 ;
  int get count => _count;

  // 数据源 包括 网络和本地

  // 内存数据

  void getWeatherData(
      BuildContext context, {
        bool isRefresh = false,
      }) async {
    if (isRefresh) notifyListeners();
  }

  void addCount() {
    _count++ ;
    notifyListeners();
  }

}
